<?php

use console\db\Migration;

/**
 * 球迷学院相关数据表
 *
 * @author emhome <emhome@163.com>
 * @since 2.0
 */
class m190102_180250_t_college extends Migration {

    /**
     * {@inheritdoc}
     */
    public function up() {

        /**
         * 成就表
         * @table `college_achieve`
         */
        $this->tableBuilder([
            'name' => 'college_achieve',
            'comment' => '成就表',
            'columns' => [
                'id' => $this->primaryKey(),
                'name' => $this->string(50)->notNull()->defaultValue('')->comment('成就名称'),
                'condition' => $this->string(255)->notNull()->defaultValue('')->comment('达成条件'),
                'stars' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('星星条件'),
                'days' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('周期条件'),
                'begin_time' => $this->unixTimestamp()->comment('限定活动开始时间'),
                'end_time' => $this->unixTimestamp()->comment('限定活动截止时间'),
                'prop_id' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('奖励道具ID'),
                'prop_num' => $this->smallInteger(6)->unsigned()->notNull()->defaultValue(0)->comment('奖励数量'),
                'img_default' => $this->char(255)->notNull()->defaultValue('')->comment('默认图标'),
                'img_unfinished' => $this->char(255)->notNull()->defaultValue('')->comment('待领取图标'),
                'img_finished' => $this->char(255)->notNull()->defaultValue('')->comment('完成图标'),
                'user_count' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('获得人数'),
                'type' => $this->tinyint(1)->unsigned()->notNull()->defaultValue(1)->comment('成就类型'),
                'describe' => $this->string(255)->defaultValue('')->comment('获取规则'),
                'sort' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('排序'),
                'status' => $this->tinyint(1)->notNull()->defaultValue(10)->comment('状态'),
                'created_at' => $this->unixTimestamp()->comment('创建时间'),
                'updated_at' => $this->unixTimestamp()->comment('更新时间'),
                'deleted_at' => $this->unixTimestamp()->comment('删除时间'),
            ]
        ]);

        /**
         * 关卡表
         * @table `college_chapter`
         */
        $this->tableBuilder([
            'name' => 'college_chapter',
            'comment' => '关卡表',
            'columns' => [
                'id' => $this->primaryKey(),
                'name' => $this->string(50)->notNull()->defaultValue('')->comment('关卡名称'),
                'num' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('关卡题目数量'),
                'grade_ratio' => $this->char(255)->notNull()->defaultValue('')->comment('难度比例'),
                'front_num' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('前端显示数量'),
                'pass_num' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('通关星星数量'),
                'unlock_num' => $this->char(255)->notNull()->defaultValue('')->comment('解锁星星数量'),
                'have_num' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('已分配题目数量'),
                'allot' => $this->tinyint(1)->unsigned()->notNull()->defaultValue(1)->comment('是否已分配完成'),
                'status' => $this->tinyint(1)->notNull()->defaultValue(10)->comment('状态'),
                'created_at' => $this->unixTimestamp()->comment('创建时间'),
                'updated_at' => $this->unixTimestamp()->comment('更新时间'),
                'deleted_at' => $this->unixTimestamp()->comment('删除时间'),
            ]
        ]);

        /**
         * 题目表
         * @table `college_question`
         */
        $this->tableBuilder([
            'name' => 'college_question',
            'comment' => '题目表',
            'columns' => [
                'id' => $this->primaryKey(),
                'content' => $this->string(255)->notNull()->defaultValue('')->comment('题目内容'),
                'grade' => $this->tinyint(1)->unsigned()->notNull()->defaultValue(0)->comment('难度级别'),
                'chapter_id' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('所属关卡ID'),
                'user_id' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('用户ID'),
                'type' => $this->tinyint(1)->unsigned()->notNull()->defaultValue(1)->comment('是否图片0否1是'),
                'right_nums' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('答对次数'),
                'wrong_nums' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('答错次数'),
                'status' => $this->tinyint(1)->notNull()->defaultValue(10)->comment('状态'),
                'created_at' => $this->unixTimestamp()->comment('创建时间'),
                'updated_at' => $this->unixTimestamp()->comment('更新时间'),
                'deleted_at' => $this->unixTimestamp()->comment('删除时间'),
            ]
        ]);

        /**
         * 答案表
         * @table `college_answer`
         */
        $this->tableBuilder([
            'name' => 'college_answer',
            'comment' => '答案表',
            'columns' => [
                'id' => $this->primaryKey(),
                'question_id' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('题目ID'),
                'content' => $this->string(50)->notNull()->comment('题目内容'),
                'char' => $this->char(20)->notNull()->comment('字母编号'),
                'right' => $this->tinyint(1)->notNull()->defaultValue(10)->comment('是否正确答案'),
                'choose_count' => $this->tinyint(1)->notNull()->defaultValue(10)->comment('选择人数'),
                'status' => $this->tinyint(1)->notNull()->defaultValue(10)->comment('状态'),
                'created_at' => $this->unixTimestamp()->comment('创建时间'),
                'updated_at' => $this->unixTimestamp()->comment('更新时间'),
                'deleted_at' => $this->unixTimestamp()->comment('更新时间'),
            ]
        ]);

        /**
         * 勋章表
         * @table `college_medal`
         */
        $this->tableBuilder([
            'name' => 'college_medal',
            'comment' => '勋章表',
            'columns' => [
                'id' => $this->primaryKey(),
                'name' => $this->string(50)->notNull()->defaultValue('')->comment('勋章名称'),
                'right_num' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('达成条件(答对题目)'),
                'unfinished_img' => $this->char(255)->notNull()->defaultValue('')->comment('未完成图标'),
                'finished_img' => $this->char(255)->notNull()->defaultValue('')->comment('完成图标'),
                'prop_id' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('奖励道具ID'),
                'prop_num' => $this->smallInteger(6)->unsigned()->notNull()->defaultValue(0)->comment('奖励数量'),
                'user_count' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('获得人数'),
                'status' => $this->tinyint(1)->notNull()->defaultValue(10)->comment('状态'),
                'created_at' => $this->unixTimestamp()->comment('创建时间'),
                'updated_at' => $this->unixTimestamp()->comment('更新时间'),
                'deleted_at' => $this->unixTimestamp()->comment('更新时间'),
            ]
        ]);

        /**
         * 游戏分享表
         * @table `college_share`
         */
        $this->tableBuilder([
            'name' => 'college_share',
            'comment' => '游戏分享表',
            'columns' => [
                'id' => $this->primaryKey(),
                'name' => $this->char(50)->notNull()->comment('名称'),
                'description' => $this->string(100)->comment('描述'),
                'icon' => $this->char(255)->defaultValue('')->comment('分享小图标'),
                'cover' => $this->char(255)->defaultValue('')->comment('链接图片'),
                'status' => $this->tinyint(1)->notNull()->defaultValue(10)->comment('状态'),
                'created_at' => $this->unixTimestamp()->comment('创建时间'),
                'updated_at' => $this->unixTimestamp()->comment('更新时间'),
            ]
        ]);
    }

    /**
     * {@inheritdoc}
     */
    public function down() {
        $this->dropTable('{{%college_share}}');
        $this->dropTable('{{%college_medal}}');
        $this->dropTable('{{%college_answer}}');
        $this->dropTable('{{%college_question}}');
        $this->dropTable('{{%college_chapter}}');
        $this->dropTable('{{%college_achieve}}');
    }

}
